package com.hytc.mymall.pop;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.hytc.mymall.R;
import com.hytc.mymall.activity.explain.ConsumptionSeriesActivity;
import com.hytc.mymall.activity.explain.MerchantCreditActivity;
import com.hytc.mymall.activity.explain.UnionWelfareRankActivity;
import com.hytc.mymall.utils.BaseTools;

/**
 * Created by Administrator on 2016/12/1.
 */

public class MainMoretPop implements View.OnClickListener
{
    private Activity activity;
    private InputMethodManager imm;
    private ImageView iv;
    public PopupWindow pop;

    public MainMoretPop(final Activity activity, final ImageView iv) {
        this.activity = activity;
        this.iv = iv;
        final View inflate = LayoutInflater.from((Context)activity).inflate(R.layout.pop_mainmore, (ViewGroup)null);
        this.imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        this.pop = new PopupWindow(inflate, BaseTools.dip2px((Context)activity, 80.0f), -2, true);
        final LinearLayout linearLayout = (LinearLayout)inflate.findViewById(R.id.ll_pop_yhxz);
        final LinearLayout linearLayout2 = (LinearLayout)inflate.findViewById(R.id.ll_pop_lsgg);
        final LinearLayout linearLayout3 = (LinearLayout)inflate.findViewById(R.id.ll_pop_sjxy);
        final LinearLayout linearLayout4 = (LinearLayout)inflate.findViewById(R.id.ll_pop_xfxl);
        linearLayout.setOnClickListener(this);
        linearLayout2.setOnClickListener(this);
        linearLayout3.setOnClickListener(this);
        linearLayout4.setOnClickListener(this);
        this.pop.setOnDismissListener((PopupWindow.OnDismissListener)new PopupWindow.OnDismissListener() {
            public void onDismiss() {
            }
        });
    }

    public void Show(final Handler handler, final int n, final EditText softKeyboardShow) {
        this.setSoftKeyboardShow(softKeyboardShow);
        new Thread() {
            @Override
            public void run() {
                final Message obtain = Message.obtain();
                obtain.what = n;
                handler.sendMessageDelayed(obtain, 100L);
            }
        }.start();
    }

    public void onClick(final View view) {
        switch (view.getId()) {
            case R.id.ll_pop_yhxz: {
                final Intent intent = new Intent((Context)this.activity, (Class)UnionWelfareRankActivity.class);
                intent.putExtra("noticetype", 21);
                this.activity.startActivity(intent);
                this.pop.dismiss();
            }
            break;
            case R.id.ll_pop_lsgg: {
                final Intent intent2 = new Intent((Context)this.activity, (Class)UnionWelfareRankActivity.class);
                intent2.putExtra("noticetype", 20);
                this.activity.startActivity(intent2);
                this.pop.dismiss();
            }
            break;
            case R.id.ll_pop_sjxy: {
                this.activity.startActivity(new Intent((Context)this.activity, (Class)MerchantCreditActivity.class));
                this.pop.dismiss();
            }
            break;
            case R.id.ll_pop_xfxl: {
                this.activity.startActivity(new Intent((Context)this.activity, (Class)ConsumptionSeriesActivity.class));
                this.pop.dismiss();
            }
            break;
        }
    }

    public void setSoftKeyboardShow(final EditText editText) {
        if (this.imm.isActive()) {
            this.imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
        }
    }

    public void showPop() {
        this.pop.setBackgroundDrawable((Drawable)new ColorDrawable(0));
        this.pop.showAsDropDown((View)this.iv, 0, 0);
        this.pop.setAnimationStyle(2131492966);
        this.pop.setFocusable(true);
        this.pop.setOutsideTouchable(false);
        this.pop.setInputMethodMode(1);
        this.pop.setSoftInputMode(16);
        this.pop.update();
    }
}

